package handler

import (
	"github.com/gin-gonic/gin"
	"choujiang/common/models"
	"choujiang/common/utils"
	"choujiang/common/consts"
	"strconv"
	"choujiang/box_server/service"
)

func GetCoinsLog(c *gin.Context) {
	form := c.Request.Form
	uniqueId := form.Get("uniqueId")
	pageNo := form.Get("pageNo")
	pageSize := form.Get("pageSize")
	aType := form.Get("type")
	int64Type, _ := strconv.ParseInt(aType, 10, 64)
	intPageNo, _ := strconv.Atoi(pageNo)
	intPageSize, _ := strconv.Atoi(pageSize)
	user := model.GetUserByUniqueId(uniqueId)
	if user == nil {
		utils.Error(consts.ErrUserNotFound, c)
		return
	}
	log := service.GetCoinsLog(user.Id, int64Type, intPageNo, intPageSize)
	for i := 0; i < len(log); i++ {
		log[i].Coins = utils.Decimal(log[i].Coins)
	}
	utils.JSON(log, c)
}
